﻿using System.Xml.Serialization;

namespace CleanSVG
{
    public class SVGCleanOptions
    {
		public bool ExtractLargeImages = false;
        public bool InsertXlinkNamespace = true;
        public bool RemoveForeignNamespaceStuff = true;
        public bool RemoveComments = true;
		public bool RemoveMetadataBlocks = true;
		public bool RemoveSyntheticTitles = true;
        public bool RemoveAllTitles = false;
        public bool RemoveAllDescs = false;
        public bool RemoveAllForeignObjects = true;
        public bool RemoveAllSwitchTags = true;
        public bool RemoveClipPaths = false;
        public bool RemoveFilters = true;
        public bool RemoveFonts = true;
        public bool ReduceFloatingPointPrecision = true;
        public bool RemoveUnreferencedIDs = true;
        public bool AddOverflowVisibleToMarkers = true;
        public bool ConvertAttributesToStyle = true;
        public bool ConvertStyleToClass = true;
        public bool CollapseMultipleClassAttributes = true;
        public bool RemoveSymbolElementsWithoutIDs = true;
        public bool ConvertCircularEllipsesToCircles = true;
        public bool ConvertSimplePathsToBasicShapes = true;
		public bool ConvertTspansToText = false;
        public bool RemoveExcessSpaceInPathData = true;
        public bool RemoveEmptyStructureElements = true;
        public bool RemoveUnneededGroupElements = true;
        public bool CleanUpWhitespace = false;
        public bool ConvertXMLSpacePresrve = true;
        public bool BreakUpSuperLongPaths = false;
        public bool WrapLongPathsPolygonsAndPolylines = true;
		public bool RemoveViewboxDirective = false;
		public bool SaveReferenceImageFromVisioFiles = false;

        public int DigitsOfFloatingPointPrecision = 3;

        public void Save()
        {
            var xs = new XmlSerializer(this.GetType());
            using (var sw = System.IO.File.CreateText(SettingsFileFullPath))
            {
                xs.Serialize(sw, this);
                sw.Close();
            }
        }

        public static SVGCleanOptions Load()
        {
            SVGCleanOptions settings;

            if (System.IO.File.Exists(SettingsFileFullPath))
            {
                var xs = new XmlSerializer(typeof(SVGCleanOptions));
                using (var sw = System.IO.File.OpenText(SettingsFileFullPath))
                {
                    settings = xs.Deserialize(sw) as SVGCleanOptions;
                    sw.Close();
                }
            }
            else
            {
                settings = new SVGCleanOptions();
            }

            return settings;
        }

        private static string SettingsFileFullPath
        {
            get { return System.Windows.Forms.Application.UserAppDataPath + @"\settings.xml"; }
        }

    }
}
